package com.edu.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyAspect {

    /**
     * @Before修饰的方法 表示是切面的一个前置通知
     */

    @Pointcut("execution(* com.edu.service..*.*(..))")
    public void pt1(){}

    @Before("pt1()")
    public void before(JoinPoint jt){
        System.out.println(jt.getSignature().getName()+"执行了 切面的 前置通知");
    }


    @AfterReturning(pointcut="pt1()",returning="result")
    public void afterR(JoinPoint jt,Object result){
        System.out.println("执行了后置返回通知");
    }



    @AfterThrowing(pointcut="pt1()",throwing = "e")
    public void afterT(JoinPoint jt,Exception e){
        System.out.println("执行了后置异常通知"+e);
    }

    @After("pt1()")
    public void after(){
        System.out.println("执行了后置 返回通知");
    }


    @Around("pt1()")
    public Object around(ProceedingJoinPoint pjt) throws Throwable {
        System.out.println("环绕通知 前置处理");
        Object result = pjt.proceed();
        System.out.println("环绕通知 后置处理");
        return result;
    }
}
